package com.yoomiito.app.present.home;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseLazyFragmentPresenter;
import com.yoomiito.app.model.bean.NavInfo;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.fragment.HomeFragment;
import com.yoomiito.app.utils.NetworkUtils;

import java.util.List;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class HomePresenter extends BaseLazyFragmentPresenter<HomeFragment> {


    public HomePresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getNavigates(String navId){
        if (NetworkUtils.checkNetPermission(getV().getContext())){
            return;
        }
        YmApi.getYmService().getNavigates(navId)
                .compose(getV().bindToLifecycle())
                .compose(XApi.<List<NavInfo>>getApiTransformerData())
                .compose(XApi.<List<NavInfo>>getScheduler())
                .subscribe(new ApiSubscriber<List<NavInfo>>(handleException()) {
                    @Override
                    public void onSuccess(List<NavInfo> navInfos) {
                        getV().getNavInfos(navInfos);
                    }

                    @Override
                    public void onFail(ApiException error) {

                    }
                });
    }

}
